#include <iostream>
using namespace std;

void partitionArray(int arr[], int n) {
    int left = 0;
    int right = n - 1;
    while (left <= right) {
        while (left <= right && arr[left] < 0) {
            left++;
        }
        while (left <= right && arr[right] >= 0) {
            right--;
        }
        if (left < right) {
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
            left++;
            right--;
        }
    }
}

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) {
            break;
        }
        int* arr = new int[n];
        for (int i = 0; i < n; i++) {
            cin >> arr[i];
        }
        partitionArray(arr, n);
        for (int i = 0; i < n; i++) {
            cout << arr[i];
            if (i != n - 1) {
                cout << " ";
            }
        }
        cout << endl;
        delete[] arr;
    }
    return 0;
}